package com.house.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.house.common.core.controller.BaseController;
import com.house.common.core.domain.AjaxResult;
import com.house.common.core.domain.entity.House;
import com.house.common.core.domain.entity.User;
import com.house.common.core.page.TableDataInfo;
import com.house.system.service.IHouseService;
import com.house.system.service.IUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.house.system.domain.Pay;
import com.house.system.service.IPayService;

/**
 * 缴纳租金Controller
 *
 * @author tc
 * @date 2022-02-25
 */
@RestController
@RequestMapping("/domain/pay")
public class PayController extends BaseController {
    @Autowired
    private IPayService payService;

    @Autowired
    private IHouseService houseService;

    @Autowired
    private IUserService userService;

    /**
     * 查询缴纳租金列表
     */
    @PreAuthorize("@ss.hasPermi('domain:pay:list')")
    @GetMapping("/list")
    public TableDataInfo list(Pay pay) {
        startPage();
        List<Pay> list = payService.selectPayList(pay);
        return getDataTable(list);
    }

    /**
     * 获取缴纳租金详细信息
     */
    @PreAuthorize("@ss.hasPermi('domain:pay:query')")
    @GetMapping(value = "/{payId}/{houseId}/{userId}")
    public AjaxResult getInfo(@PathVariable("payId") Long payId, @PathVariable("houseId") Long houseId, @PathVariable("userId") Long userId) {
        AjaxResult ajax = AjaxResult.success();
        Pay pay = payService.selectPayByPayId(payId);
        User user = userService.selectUserByUserId(userId);
        House house = houseService.selectHouseByHouseId(houseId);
        ajax.put("pay", pay);
        ajax.put("house", house);
        ajax.put("user", user);
        return ajax;
    }

    /**
     * 新增缴纳租金
     */
    @PreAuthorize("@ss.hasPermi('domain:pay:add')")
    @PostMapping
    public AjaxResult add(@RequestBody Pay pay) {
        return toAjax(payService.insertPay(pay));
    }

    /**
     * 租客缴纳租金
     */
    @PreAuthorize("@ss.hasPermi('domain:pay:handle')")
    @PutMapping
    public AjaxResult edit(@RequestBody Pay pay) {
        return toAjax(payService.updatePay(pay));
    }

    /**
     * 删除缴纳租金
     */
    @PreAuthorize("@ss.hasPermi('domain:pay:remove')")
    @DeleteMapping("/{payIds}")
    public AjaxResult remove(@PathVariable Long[] payIds) {
        return toAjax(payService.deletePayByPayIds(payIds));
    }
}
